package cn.edu.hqu.cst.lecture02_02.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.nio.file.NoSuchFileException;

@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(FileStorageException.class)
    public ResponseEntity<String> handleFileStorageException(FileStorageException ex) {
        // 返回500内部服务器错误状态
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件存储错误: " + ex.getMessage());
    }

    @ExceptionHandler(NoSuchFileException.class)
    public ResponseEntity<String> handleNoSuchFileException(NoSuchFileException ex) {
        
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body("文件未找到: " + ex.getMessage());
    }

    

    @ExceptionHandler(IllegalArgumentException.class)
    public ResponseEntity<String> handleIllegalArgumentException(IllegalArgumentException ex) {
       
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("非法参数: " + ex.getMessage());
    }
}

    